package com.niuwa.p2p.core.utils;

import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.UUID;
import java.util.Vector;
import java.util.regex.Pattern;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.DateUtils;

public class StringUtil {

	public static DecimalFormat df = new DecimalFormat("000000000000");

	private static DecimalFormat RMB_FMT = new DecimalFormat("#,##0");

	/**
	 * Convert the cents (in FEN) into RMB. For example, 12345670 is converted
	 * into "123,456.70"
	 * 
	 * @param cents
	 *            the cents in FEN.
	 * @return the string converted from the cents.
	 */
	public static String toRMB(long cents) {
		long yuan = cents / 100;
		cents %= 100;
		return ((RMB_FMT.format(yuan) + '.') + cents / 10) + cents % 10;
	}

	/**
	 * Convert the cents (in FEN) into RMB. For example, 12345670 is converted
	 * into "123,456.70". The difference between this method and the
	 * {@link #toRMB(long)} method is how to deal with a cents which has no
	 * fraction part. Take 1234 as an example, this method converts it into
	 * "1,234" whereas the {@link #toRMB(long)} method converts it into
	 * "1,234.00".
	 * 
	 * @param cents
	 *            the cents in FEN.
	 * @return the string converted from the cents.
	 */
	public static String toRMBPack(long cents) {
		long yuan = cents / 100;
		String result = RMB_FMT.format(yuan);

		cents %= 100;
		if (cents > 0)
			result += ("." + cents / 10) + cents % 10;

		return result;
	}

	/**
	 * Convert the RMB into cents (in FEN). For example, "123,456.70" is
	 * converted into 12345670.
	 * 
	 * @param rmb
	 *            the RMB
	 * @return the cents converted from the RMB.
	 * @throws ParseException
	 *             if the format of the rmb is invalid. e.g. "3.123", "12.3.7"
	 *             are both invalid. ".23", "0.23", "12.30", "12.3", "12.00",
	 *             "12", "1,234", "1234", "1,234.", "1,234.0", "1,234.00",
	 *             ".00", ".0", "." are all valid.
	 */
	public static long toCents(String rmb) throws ParseException {
		int len = rmb.length();
		long result = 0;

		int i = 0;
		repeat: while (i < len) {
			char ch = rmb.charAt(i++);
			switch (ch) {
			case ',':
				break;
			case '.':
				break repeat;
			default:
				if ('0' <= ch && ch <= '9')
					result = result * 10 + (ch - '0');
				else
					throw new ParseException(rmb, i);
			}
		}

		int j = 0;
		while (j < 2 && i < len) {
			j++;
			char ch = rmb.charAt(i++);
			if ('0' <= ch && ch <= '9')
				result = result * 10 + (ch - '0');
			else
				throw new ParseException(rmb, i);
		}

		if (i < len)
			throw new ParseException(rmb, i);

		while (j < 2) {
			j++;
			result *= 10;
		}

		return result;
	}

	/**
	 * Convert a text into HTML. For example, "<ab&c" is converted into
	 * "&lt;ab&amp;c".
	 * 
	 * @param text
	 *            the text
	 * @return the HTML converted from the text.
	 */
	public static String toHTML(String text) {
		StringBuilder result = new StringBuilder();
		int len = text.length();
		for (int i = 0; i < len; i++) {
			char ch = text.charAt(i);
			switch (ch) {
			case '<':
				result.append("&lt;");
				break;
			case '>':
				result.append("&gt;");
				break;
			case '"':
				result.append("&quot;");
				break;
			case '&':
				result.append("&amp;");
				break;
			default:
				result.append(ch);
			}
		}
		return result.toString();
	}

	// Note: To avoid multiple thread issue, please do not define
	// SimpleDateFormat object as a class variables, it should define in a
	// specific method
	// Please ues apache StringUtils method like isEmpty isNotBlank etc.

	private static SimpleDateFormat sdf = new SimpleDateFormat(
			"yyyy-MM-dd HH:mm:ss");

	/**
	 * 
	 * @param date
	 * @return yyyy-MM-dd HH:mm:ss
	 */
	public static String dateFormat(Date date) {

		if (date == null) {
			return null;
		} else {
			return sdf.format(date);
		}
	}

	private static SimpleDateFormat sdf2 = new SimpleDateFormat(
			"yyyyMMddHHmmss");

	/**
	 * @param date
	 * @return YYYYMMDD24HHMMSS
	 */
	public static String dateFormat2(Date date) {
		if (date == null) {
			return null;
		} else {
			return sdf2.format(date);
		}
	}

	private static SimpleDateFormat sdf4 = new SimpleDateFormat("yyyy-MM-dd");

	/**
	 * @param
	 * @return yyyy-MM-dd
	 */
	public static String dateFormat4(Date date) {
		if (date == null) {
			return null;
		} else {
			return sdf4.format(date);
		}
	}

	private static SimpleDateFormat sdf5 = new SimpleDateFormat("yyyy年MM月dd日");

	/**
	 * @param
	 * @return "yyyy年MM月dd日"
	 */
	public static String dateFormat5(Date date) {
		if (date == null) {
			return null;
		} else {
			return sdf5.format(date);
		}
	}

	private static SimpleDateFormat sdf6 = new SimpleDateFormat(
			"yyyy年MM月dd日 HH:mm");

	/**
	 * @param
	 * @return "yyyy年MM月dd日 HH:mm"
	 */
	public static String dateFormat6(Date date) {
		if (date == null) {
			return null;
		} else {
			return sdf6.format(date);
		}
	}

	public static String getformateDateString(Date date, String pattern) {
		SimpleDateFormat sdf = new SimpleDateFormat(pattern);
		if (date == null) {
			return null;
		} else {
			return sdf.format(date);
		}
	}

	private static SimpleDateFormat sdf3 = new SimpleDateFormat(
			"yyyy/MM/dd HH:mm");

	/**
	 * @param date
	 *            4-12 修改 yyyy/MM/dd -->yyyy/MM/dd
	 * @return yyyy/MM/dd HH:mm
	 */
	public static String dateFormat3(Date date) {
		if (date == null) {
			return null;
		} else {
			return sdf3.format(date);
		}
	}

	public static String date2String(Date date, String format) {
		if (date == null) {
			return null;
		} else {
			SimpleDateFormat sdf = new SimpleDateFormat(format);
			return sdf.format(date);
		}
	}

	/**
	 * toString
	 * 
	 * @param str
	 * @return 为null返回""
	 */
	public static String toString(Object obj) {
		return obj == null ? "" : obj.toString();
	}

	/**
	 * 获取一个不重复的字符串
	 * 
	 * @return
	 */
	public static String GetUniquelyString() {
		UUID uuid = UUID.randomUUID();
		return uuid.toString();
	}

	/**
	 * 取某天0点0分0秒
	 * 
	 * @param date
	 * @return
	 */
	public static Date getDateStart(Date date) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.set(Calendar.HOUR_OF_DAY, 0);
		calendar.set(Calendar.MINUTE, 0);
		calendar.set(Calendar.SECOND, 0);
		calendar.set(Calendar.MILLISECOND, 0);

		return calendar.getTime();
	}

	/**
	 * 取某天23点59分59秒
	 * 
	 * @param date
	 * @return
	 */
	public static Date getDateEnd(Date date) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.set(Calendar.HOUR_OF_DAY, 23);
		calendar.set(Calendar.MINUTE, 59);
		calendar.set(Calendar.SECOND, 59);
		return calendar.getTime();
	}

	/**
	 * 取得某月的第一天
	 * 
	 * @param date
	 * @return
	 */
	public static Date getFirstDayOfMonth(Date date) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.set(Calendar.HOUR_OF_DAY, 0);
		calendar.set(Calendar.MINUTE, 0);
		calendar.set(Calendar.SECOND, 0);
		calendar.set(Calendar.DAY_OF_MONTH, calendar.getMinimum(Calendar.DATE));
		return calendar.getTime();
	}

	/**
	 * 取得某月的最后一天
	 * 
	 * @param date
	 * @return
	 */
	public static Date getLastDayOfMonth(Date date) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.set(Calendar.HOUR_OF_DAY, 0);
		calendar.set(Calendar.MINUTE, 0);
		calendar.set(Calendar.SECOND, 0);
		calendar.set(Calendar.DAY_OF_MONTH,
				calendar.getActualMaximum(Calendar.DATE));
		return calendar.getTime();
	}

	/**
	 * 取得向前或向后移动N个月时间
	 * 
	 * @param date
	 * @param amount
	 * @return
	 */
	public static Date getAddMonthOfDate(Date date, int amount) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.add(Calendar.MONTH, amount);
		return calendar.getTime();
	}

	/**
	 * 取得向前或向后移动N天
	 * 
	 * @param date
	 * @param amount
	 * @return
	 */
	public static Date getAddDayOfDate(Date date, int amount) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.add(Calendar.DATE, amount);
		return calendar.getTime();
	}

	/**
	 * 取得向前或向后移动N年
	 * 
	 * @param date
	 * @param amount
	 * @return
	 */
	public static Date getAddYearOfDate(Date date, int amount) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.add(Calendar.YEAR, amount);
		return calendar.getTime();
	}

	/**
	 * 计算两个时间相差的秒数 date2-date1
	 * 
	 * @param date1
	 * @param date2
	 * @return
	 */
	public static long getDifferSecond(Date date1, Date date2) {
		return (date2.getTime() - date1.getTime()) / 1000;
	}

	/**
	 * 计算两个时间相差的天数 date2-date1
	 * 
	 * @param date1
	 * @param date2
	 * @return
	 */
	public static long getDifferDay(Date date1, Date date2) {
		// return date1.getTime() / (24*60*60*1000) - date2.getTime() /
		// (24*60*60*1000);
		return (date2.getTime() - date1.getTime()) / 86400000; // 用立即数，减少乘法计算的开销
	}

	public static long getDifferDayNoHMS(Date date1, Date date2) {
		// TimeZone gmt8 = TimeZone.getTimeZone("GMT+8");
		// TimeZone.setDefault(gmt8);
		if (date1 != null && date2 != null) {
			Calendar calendar1 = Calendar.getInstance();
			calendar1.setTime(date1);
			calendar1.set(Calendar.HOUR_OF_DAY, 0);
			calendar1.set(Calendar.MINUTE, 0);
			calendar1.set(Calendar.SECOND, 0);
			calendar1.set(Calendar.MILLISECOND, 0);

			Calendar calendar2 = Calendar.getInstance();
			calendar2.setTime(date2);
			calendar2.set(Calendar.HOUR_OF_DAY, 0);
			calendar2.set(Calendar.MINUTE, 0);
			calendar2.set(Calendar.SECOND, 0);
			calendar2.set(Calendar.MILLISECOND, 0);
			return (calendar1.getTime().getTime() - calendar2.getTime()
					.getTime()) / 86400000; // 用立即数，减少乘法计算的开销
		}
		return 0;
	}

	public static String getHtmlStringForCredit(double score, long userId) {
		int number = (int) score;
		String sb = "";
		String img = "<img src='../static/img/xxx'/>";
		String letterA = "a.gif";
		String letterB = "b.gif";
		String letterC = "c.gif";
		String letterAplus = "a+.gif";
		String letterAA = "aa.gif";
		String letterAAplus = "aa+.gif";
		String letterAAA = "aaa.gif";
		String letterAAAsub = "aaa-.gif";
		String letterAAAplus = "aaa+.gif";
		String letterAAsub = "aa-.gif";
		String letterAsub = "a-.gif";
		String letterBlevelTwo = "bb.gif";
		String letterBlevelThree = "bbb.gif";

		if (number < 61) // 小于61分 C
		{
			sb = img.replace("xxx", letterC);
		} else if (number > 60 && number < 71) // 61-70 B
		{
			sb = img.replace("xxx", letterB);
		} else if (number > 70 && number < 91) // 71-90 BB
		{
			sb = img.replace("xxx", letterBlevelTwo);
		} else if (number > 90) // 50-59 BBB
		{
			sb = img.replace("xxx", letterBlevelThree);
			if (number > 105)// && ((iCityCountNum >= 1 && ((Top4CityTotalMoney
								// >= 北上广深A && Top4CityTotalRate <
								// (int)CityRateLevel.北上广深A) ||
								// (Top16CityTotalMoney >=
								// (int)CityValueLevel.其它城市A &&
								// Top16CityTotalRate <
								// (int)CityRateLevel.其它城市A))) ||
								// (repayment12Months && repaymentNoOverdue)))
			{
				sb = img.replace("xxx", letterAsub);
			}
			if (number > 125)// && ((iCityCountNum >= 1 && ((Top4CityTotalMoney
								// >= (int)CityValueLevel.北上广深A &&
								// Top4CityTotalRate < (int)CityRateLevel.北上广深A)
								// || (Top16CityTotalMoney >=
								// (int)CityValueLevel.其它城市A &&
								// Top16CityTotalRate <
								// (int)CityRateLevel.其它城市A))) ||
								// (repayment12Months && repaymentNoOverdue)))
			{
				sb = img.replace("xxx", letterA);
			}
			if (number > 145)// && ((iCityCountNum >= 1 && ((Top4CityTotalMoney
								// >= (int)CityValueLevel.北上广深A &&
								// Top4CityTotalRate < (int)CityRateLevel.北上广深A)
								// || (Top16CityTotalMoney >=
								// (int)CityValueLevel.其它城市A &&
								// Top16CityTotalRate <
								// (int)CityRateLevel.其它城市A))) ||
								// (repayment12Months && repaymentNoOverdue)))
			{
				sb = img.replace("xxx", letterAplus);
			}

			if (number > 165)// && ((iCityCountNum >= 2 && ((Top4CityTotalMoney
								// >= (int)CityValueLevel.北上广深AA &&
								// Top4CityTotalRate <
								// (int)CityRateLevel.北上广深AA) ||
								// (Top16CityTotalMoney >=
								// (int)CityValueLevel.其它城市AA &&
								// Top16CityTotalRate <
								// (int)CityRateLevel.其它城市AA))) ||
								// (repayment36Months && repaymentNoOverdue)))
			{
				sb = img.replace("xxx", letterAAsub);
			}
			if (number > 190)// && ((iCityCountNum >= 2 && ((Top4CityTotalMoney
								// >= (int)CityValueLevel.北上广深AA &&
								// Top4CityTotalRate <
								// (int)CityRateLevel.北上广深AA) ||
								// (Top16CityTotalMoney >=
								// (int)CityValueLevel.其它城市AA &&
								// Top16CityTotalRate <
								// (int)CityRateLevel.其它城市AA))) ||
								// (repayment36Months && repaymentNoOverdue)))
			{
				sb = img.replace("xxx", letterAA);
			}
			if (number > 215)// && ((iCityCountNum >= 2 && ((Top4CityTotalMoney
								// >= (int)CityValueLevel.北上广深AA &&
								// Top4CityTotalRate <
								// (int)CityRateLevel.北上广深AA) ||
								// (Top16CityTotalMoney >=
								// (int)CityValueLevel.其它城市AA &&
								// Top16CityTotalRate <
								// (int)CityRateLevel.其它城市AA))) ||
								// (repayment36Months && repaymentNoOverdue)))
			{
				sb = img.replace("xxx", letterAAplus);
			}

			if (number > 240)// && ((iCityCountNum >= 3 && ((Top4CityTotalMoney
								// >= (int)CityValueLevel.北上广深AAAAsub &&
								// Top4CityTotalRate <
								// (int)CityRateLevel.北上广深AAAsub) ||
								// (Top16CityTotalMoney >=
								// (int)CityValueLevel.其它城市AAAplus &&
								// Top16CityTotalRate <
								// (int)CityRateLevel.北上广深AAAsub))) ||
								// (repayment24Months && repaymentNoOverdue)))
			{
				sb = img.replace("xxx", letterAAAsub);
			}
			if (number > 270)// && ((iCityCountNum >= 3 && ((Top4CityTotalMoney
								// >= (int)CityValueLevel.北上广深AAA &&
								// Top4CityTotalRate <
								// (int)CityRateLevel.北上广深AAA) ||
								// (Top16CityTotalMoney >=
								// (int)CityValueLevel.其它城市AAA &&
								// Top16CityTotalRate <
								// (int)CityRateLevel.其它城市AAA))) ||
								// (repayment30Months && repaymentNoOverdue)))
			{
				sb = img.replace("xxx", letterAAA);
			}
			if (number > 300)// && ((iCityCountNum >= 3 && ((Top4CityTotalMoney
								// >= (int)CityValueLevel.北上广深AAAplus &&
								// Top4CityTotalRate <
								// (int)CityRateLevel.北上广深AAAplus) ||
								// (Top16CityTotalMoney >=
								// (int)CityValueLevel.其它城市AAAplus &&
								// Top16CityTotalRate <
								// (int)CityRateLevel.其它城市AAAplus))) ||
								// (repayment36Months && repaymentNoOverdue)))
			{
				sb = img.replace("xxx", letterAAAplus);
			}

		}
		return sb.toString();
	}

	/**
	 * // 12位左补0 , 出参数分
	 * 
	 * @param e
	 *            单位 元
	 * @return
	 */
	public static String getString(Double e) {
		return df.format(e * 100);
	}

	/**
	 * 借款标状态
	 */

	public static Map<String, String> orderStatus = new HashMap<String, String>();
	static {
		// -1草稿,0投标进行中,1满标待审核,2还款中,3还款完成(交易结束),-2撤标,-3流标,-4审核拒绝
		orderStatus.put("0", "投标进行中");
		orderStatus.put("1", "满标待审核");
		orderStatus.put("2", "还款中");
		orderStatus.put("3", "还款完成");
		orderStatus.put("-1", "草稿");
		orderStatus.put("-2", "撤标");
		orderStatus.put("-3", "流标");
		orderStatus.put("-4", "审核拒绝");
		orderStatus.put("-5", "删除");
		orderStatus.put("-6", "等待审核");
		orderStatus.put("-7", "审核拒绝");
	}

	/**
	 * 认证名称
	 */
	public static Map<String, String> auditName = new HashMap<String, String>();
	static {
		auditName.put("101", "身份认证");
		auditName.put("102", "学历认证");
		auditName.put("103", "视频认证");
		auditName.put("104", "手机实名认证");

		auditName.put("112", "征信认证");
		auditName.put("116", "不动产认证");
		auditName.put("117", "法院数据认证");
		auditName.put("119", "银行流水认证");

		auditName.put("123", "联系方式认证");
		auditName.put("124", "现居住地址认证");
		auditName.put("125", "百度Google认证");
		auditName.put("201", "身份证图片认证");
		auditName.put("109", "公积金认证");
		auditName.put("126", "户籍认证");
	}
	/**
	 * 还款方式
	 */
	public static Map<String, String> borrowRepayType = new HashMap<String, String>();
	static {
		borrowRepayType.put("-1", "请选择");
		borrowRepayType.put("1", "每月等额本息还款");
		borrowRepayType.put("2", "每月等本金还款");
		borrowRepayType.put("3", "每月还息到期还本(按月算)");
		borrowRepayType.put("4", "到期一次还本付息");
		borrowRepayType.put("5", "每月还息到期还本(按日算)");
	}
	/**
	 * 是否担保
	 */
	public static Map<String, String> isWarrant = new HashMap<String, String>();
	static {
		isWarrant.put("0", "未选择担保");
		isWarrant.put("1", "选择担保");
	}
	/**
	 * 投标方式
	 */
	public static Map<String, String> bidType = new HashMap<String, String>();
	static {
		bidType.put("0", "自动投标");
		bidType.put("1", "手动投标");
		bidType.put("3", "理财投标");
		bidType.put("7", "畅盈宝投标");
	}
	/**
	 * 借款目的
	 */
	public static Map<String, String> borrowGoal = new HashMap<String, String>();
	static {

		borrowGoal.put("120101", "享装修");
		borrowGoal.put("120102", "享旅游");
		borrowGoal.put("120103", "享购车");
		borrowGoal.put("120104", "享教育");

		borrowGoal.put("120105", "满标有礼");
		borrowGoal.put("120201", "个人消费借款");
		borrowGoal.put("120202", "个人创业借款");
		borrowGoal.put("120203", "短期周转借款");
		borrowGoal.put("120204", "其他借款");

	}
	/**
	 * 资金交易类型
	 */
	public static Map<String, String> accountHistory = new HashMap<String, String>();
	static {
		accountHistory.put("0", "首次充值");
		accountHistory.put("1", "首次取现");

		accountHistory.put("2", "充值");
		accountHistory.put("3", "充值手续费");
		accountHistory.put("4", "提现");
		accountHistory.put("5", "提现手续费");

		accountHistory.put("6", "借款保证金");
		accountHistory.put("7", "投标担保金");
		accountHistory.put("8", "投标金额");
		accountHistory.put("9", "借款保证金");
		accountHistory.put("10", "投标担保金");
		accountHistory.put("11", "投标担保金");
		accountHistory.put("12", "投标担保金");
		accountHistory.put("13", "投标金额");
		accountHistory.put("14", "投标金额");
		accountHistory.put("15", "投标金额");
		accountHistory.put("16", "借款服务费");
		accountHistory.put("17", "借款服务费");
		accountHistory.put("18", "扣除保证金");
		accountHistory.put("19", "分得保证金");
		accountHistory.put("20", "还款");
		accountHistory.put("21", "收款");
		accountHistory.put("22", "逾期还款,罚息");
		accountHistory.put("23", "逾期还款,罚息");
		accountHistory.put("24", "提前还款,违约");
		accountHistory.put("25", "提前还款,违约");
		accountHistory.put("26", "发标审核拒绝/撤标,平台分得剩余保证金");
		accountHistory.put("27", "逾期赔付,出");
		accountHistory.put("28", "逾期赔付,入");
		// #### new

	}
	/**
	 * 资金记录--收支类型
	 */
	public static Map<String, String> action = new HashMap<String, String>();
	static {
		action.put("1", "入账");
		action.put("-1", "出账");
		action.put("-2", "冻结");
		action.put("2", "解冻");
		action.put("3", "用户充值");
		action.put("-3", "用户取现");
	}

	/**
	 * 规避solr 的特殊符号
	 * 
	 * @param s
	 * @return
	 */
	public static String escapeQueryChars(String s) {
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < s.length(); i++) {
			char c = s.charAt(i);
			// These characters are part of the query syntax and must be escaped
			if (c == '\\' || c == '+' || c == '-' || c == '!' || c == '('
					|| c == ')' || c == ':' || c == '^' || c == '[' || c == ']'
					|| c == '\"' || c == '{' || c == '}' || c == '~'
					|| c == '*' || c == '?' || c == '|' || c == '&' || c == ';'
					|| Character.isWhitespace(c)) {
				sb.append('\\');
			}
			sb.append(c);
		}
		return sb.toString();
	}

	/**
	 * html to text
	 * 
	 * @param inputString
	 * @return
	 */
	public static String htmlToText(String inputString) {
		String htmlStr = inputString; // 含html标签的字符串
		String textStr = "";
		java.util.regex.Pattern p_script;
		java.util.regex.Matcher m_script;
		java.util.regex.Pattern p_style;
		java.util.regex.Matcher m_style;
		java.util.regex.Pattern p_html;
		java.util.regex.Matcher m_html;

		/*
		 * java.util.regex.Pattern p_html1; java.util.regex.Matcher m_html1;
		 */

		try {
			String regEx_script = "<[\\s]*?script[^>]*?>[\\s\\S]*?<[\\s]*?\\/[\\s]*?script[\\s]*?>"; // 定义script的正则表达式{或<script[^>]*?>[\\s\\S]*?<\\/script>
			String regEx_style = "<[\\s]*?style[^>]*?>[\\s\\S]*?<[\\s]*?\\/[\\s]*?style[\\s]*?>"; // 定义style的正则表达式{或<style[^>]*?>[\\s\\S]*?<\\/style>
			String regEx_html = "<[^>]+>"; // 定义HTML标签的正则表达式

			p_script = Pattern.compile(regEx_script, Pattern.CASE_INSENSITIVE);
			m_script = p_script.matcher(htmlStr);
			htmlStr = m_script.replaceAll(""); // 过滤script标签

			p_style = Pattern.compile(regEx_style, Pattern.CASE_INSENSITIVE);
			m_style = p_style.matcher(htmlStr);
			htmlStr = m_style.replaceAll(""); // 过滤style标签

			p_html = Pattern.compile(regEx_html, Pattern.CASE_INSENSITIVE);
			m_html = p_html.matcher(htmlStr);
			htmlStr = m_html.replaceAll(""); // 过滤html标签

			textStr = htmlStr;

		} catch (Exception e) {
			e.printStackTrace();
		}

		return textStr;// 返回文本字符串
	}

	/**
	 * 生成随机密码
	 * 
	 * @param pwd_len
	 *            长度
	 * @return
	 */
	public static String genRandomPwd(int pwd_len) {
		// 35是因为数组是从0开始的，26个字母+10个数字
		final int maxNum = 36;
		int i; // 生成的随机数
		int count = 0; // 生成的密码的长度
		char[] str = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k',
				'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
				'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };

		StringBuffer sb = new StringBuffer("");
		Random r = new Random();
		while (count < pwd_len) {
			// 生成随机数，取绝对值，防止生成负数，

			i = Math.abs(r.nextInt(maxNum)); // 生成的数最大为36-1

			if (i >= 0 && i < str.length) {
				sb.append(str[i]);
				count++;
			}
		}

		return sb.toString();
	}

	public static long getDifferDayForMonth(Integer monthTerm, Date startDate) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(startDate);
		// calendar.set(Calendar.MONTH, monthTerm);
		Calendar calendar1 = Calendar.getInstance();
		calendar1.setTime(startDate);
		calendar1.set(Calendar.MONTH, monthTerm);
		long days = StringUtil.getDifferDayNoHMS(calendar.getTime(),
				calendar1.getTime());
		return days;
	}

	public static String makeNbsp(int count) {
		StringBuffer sBuffer = new StringBuffer();
		for (int i = 0; i < count; i++) {
			sBuffer.append("&nbsp;");
		}
		return sBuffer.toString();
	}

	/**
	 * 获得当前日期和时间
	 * 
	 * @throws ParseException
	 */
	public static Date getCurDateTime() throws ParseException {
		String dateStr = dateFormat(new Date());
		return String2DateTime(dateStr);
	}

	/**
	 * 获得当前日期和时间
	 */
	public static Date getCurDateTimeNOException() {
		Date result = null;
		try {
			String dateStr = dateFormat(new Date());
			result = String2DateTime(dateStr);
		} catch (ParseException e) {
			result = null;
		}

		return result;
	}

	/**
	 * 字符串转换为时间(带时分秒) 需要迁移到专门的DateUtil
	 * 
	 * @param str
	 * @return
	 * @throws ParseException
	 */
	public static Date String2DateTime(String str) throws ParseException {
		return DateUtils.parseDate(str, new String[] { "yyyy-MM-dd HH:mm:ss",
				"yyyyMMddHHmmss" });
	}

	/**
	 * 字符串转换为日期(只是年月日,不带时分秒) 需要迁移到专门的DateUtil
	 * 
	 * @param str
	 * @return
	 * @throws ParseException
	 */
	public static Date String2Date(String str) throws ParseException {
		return DateUtils.parseDate(str,
				new String[] { "yyyy-MM-dd", "yyyyMMdd" });
	}

	/**
	 * 字符串转换为日期(只是年月日,不带时分秒) 需要迁移到专门的DateUtil
	 * 
	 * @param str
	 * @return
	 * @throws ParseException
	 */
	public static Date String2DateNOException(String str, Date defaultValue) {
		Date result = null;
		if (StringUtils.isEmpty(str)) {
			result = defaultValue;
		} else {
			try {
				result = DateUtils.parseDate(str, new String[] { "yyyy-MM-dd",
						"yyyyMMdd" });
			} catch (ParseException e) {
				result = defaultValue;
			}
		}

		return result;
	}

	/**
	 * 字符串转换为日期(只是年月日,不带时分秒) 需要迁移到专门的DateUtil
	 * 
	 * @param str
	 * @return
	 * @throws ParseException
	 */
	public static Date String2DateNOException(String str) {
		Date result = null;
		try {
			result = String2DateNOException(str, getCurDateTime());
		} catch (ParseException e) {
			e.printStackTrace();
		}

		return result;
	}

	/**
	 * 简易的标的密码
	 * 
	 * @return
	 */
	public static String generateSimpleOrderPwd(Long orderId, Date createTime) {
		String passWord = String.valueOf(orderId + createTime.getTime());
		return passWord.substring(passWord.length() - 6, passWord.length());
	}

	public static boolean isNullOrEmpty(String str) {
		return null == str || str.trim().equals("");
	}

	public static String convertNullOrEmpty(String str) {
		return (isNullOrEmpty(str)) ? "" : str;
	}

	/**
	 * 判断是否为null或""
	 * 
	 * @param object
	 * @return
	 */
	public static boolean isNullOrEmpty2(Object object) {
		boolean flag = false;
		if (object != null) {
			if (object instanceof String) {
				if (!"".equals(object)) {
					flag = true;
				}
			} else {
				flag = true;
			}
		}
		return flag;
	}

	/**
	 * 传入BigDecimal类型金额，转换成分，
	 * 大于1万，则以万元为单位
	 * 不足1万，则以元为单位
	 * 3位1逗，有小数则保留，无小数不显示
	 * @param cents
	 * @return
	 */
	public static String formatMoney(BigDecimal money) {
		DecimalFormat df = new DecimalFormat("##,###.##");
		money = money.multiply(new BigDecimal(100));
		
		long cents = money.longValue();
		String amountStr = "";
		long yuan = cents / 100;
		long fen = cents % 100;

		if (yuan > 10000) {
			long wanyuan = yuan / 10000;
			long other = yuan % 10000;
			while (other > 0) {
				if ((other % 10) > 0) {
					break;
				}
				other = other / 10;
			}
			amountStr = other > 0 ? df.format(wanyuan) + "." + other : df.format(wanyuan);
		} else {
			if(fen > 0){
				amountStr = df.format(yuan) + "." + fen;
			}else{
				amountStr = df.format(yuan);
			}
		}

		return amountStr;
	}

	/**
	 * 元转换成万元
	 * 
	 * @param yuan
	 * @return
	 */
	public static String formatWan(BigDecimal yuan) {
		String amountStr = "";
		BigDecimal wan = new BigDecimal(10000);
		if (yuan.compareTo(wan) >= 0) {
			BigDecimal wanyuan = yuan.divide(wan, 4, BigDecimal.ROUND_HALF_UP);

			amountStr = wanyuan + "万";
		} else {
			amountStr = yuan.toString();
		}

		return amountStr;
	}

	public static String getTransNo(int seq) {
		String temp = seq + "";
		String pre_word = "";
		if (temp.length() < 5) {
			int count = 5 - temp.length();
			while (count > 0) {
				pre_word += "0";
				count--;
			}
			temp = pre_word + temp;
		}

		return "ZR-" + getformateDateString(new Date(), "yyyyMMdd") + "-"
				+ temp;
	}

	/**
	 * 屏蔽部分信息保留前后三位
	 * 
	 * @param str
	 *            要替换的字符串
	 * @return
	 */
	public static String hiddenString(String str) {
		String str1 = str.substring(0, 3);
		String str2 = str.substring(str.length() - 3, str.length());
		String newStr = str1 + "******" + str2;
		return newStr;
	}

	/**
	 * 隐藏名字
	 * 
	 * @param name
	 * @return
	 * @throws Exception
	 */
	public static String hiddenName(String name) throws Exception {
		String nameStr = "";
		if (null != name && !"".equals(name)) {
			nameStr = name.substring(0, 1) + "***";
		}
		return nameStr;
	}

	public static String assemblingData(Map<String, Object> map) {

		if (map.get("first") != null) {

		}

		return "";
	}

	/**
	 * 格式化，保留2位小数
	 * 
	 * @param num
	 * @return
	 */
	public static String formatRate(BigDecimal num) {
		DecimalFormat df = new DecimalFormat("##.##");
		return df.format(num);
	}

	/**
	 * 货币化
	 * 
	 * @param money
	 * @return
	 */
	@SuppressWarnings("static-access")
	public static String formatRMB(BigDecimal money) {
		NumberFormat currency = NumberFormat.getCurrencyInstance();
		// 添加地区国际化语言
		currency.getInstance(Locale.CHINA);// getInstance(Locale.CHINA);
		Locale.setDefault(Locale.CHINA);// 设置JVM虚拟机默认语言格式
		return currency.format(money);
	}

	/**
	 * 通过毫秒数转换成指定格式的日期
	 * 
	 * @param milliseconds
	 * @param pattern
	 * @return
	 */
	public static String formatMilliseconds(long milliseconds, String pattern) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTimeInMillis(milliseconds);

		DateFormat df = new SimpleDateFormat(pattern);

		return df.format(calendar.getTime());
	}

	public static void main(String[] args) throws ParseException {
		BigDecimal big = new BigDecimal(1000.0023);
		System.out.println(formatMoney(big));
		// System.out.println(getTransNo(2));
		/*
		 * String time = "2014-08-25 14:26:38.0".substring(0, 19); Date date =
		 * sdf.parse(time); System.out.println(dateFormat6( date ));
		 */
		/*
		 * DecimalFormat df = new DecimalFormat("##.##");
		 * 
		 * BigDecimal num1 = new BigDecimal(22.5); BigDecimal num2 = new
		 * BigDecimal(23.44); BigDecimal num3 = new BigDecimal(22.00);
		 * BigDecimal num4 = new BigDecimal(21); BigDecimal num5 = new
		 * BigDecimal(233331.08);
		 * 
		 * System.out.println(df.format(num1));
		 * System.out.println(df.format(num2));
		 * System.out.println(df.format(num3));
		 * System.out.println(df.format(num4));
		 * System.out.println(df.format(num5));
		 */

		/*
		 * StringUtil stringUtil = new StringUtil();
		 * 
		 * String string = stringUtil.getURLParams("a");
		 * System.out.println(string);
		 */

	}
	
	/**-----------------------------------------------------------------------------------*/
	/**
	 * Insert the method's description here. Creation date: (2/22/2002 11:21:30
	 * AM)
	 * 
	 * @return java.lang.String
	 * @param str
	 *            java.lang.String
	 */
	public static String filterString(String str) {
		if (str == null) {
			return "";
		}
		StringBuffer tempStr = new StringBuffer(str);
		int i;
		for (i = 0; i < tempStr.length(); i++) {
			if (tempStr.charAt(i) == '\'') {
				tempStr.insert(i, '\'');
				i++;
			}
		}
		return tempStr.toString();
	}

	/**
	 * Insert the method's description here. Creation date: (3/14/2003 1:39:40
	 * PM)
	 * 
	 * @return boolean
	 */
	public static boolean isEmpty(String str) {
		return (str == null || str.trim().equals(""));
	}

	public static Boolean isPassword(String password) {
		String parttern = "^[a-zA-Z0-9]{6,20}$";
		if (Pattern.matches(parttern, password)) {
			return Boolean.TRUE;
		} else {
			return Boolean.FALSE;
		}
	}

	/**
	 * Constructs an array of string token for the specified string. All
	 * characters in the <code>delim</code> argument are the delimiters for
	 * separating tokens.
	 * <p>
	 * If the <code>returnDelims</code> flag is <code>true</code>, then the
	 * delimiter characters are also returned as tokens. Each delimiter is
	 * returned as a string of length one. If the flag is <code>false</code>,
	 * the delimiter characters are skipped and only serve as separators between
	 * tokens.
	 * <p>
	 * Note that if <tt>delim</tt> is <tt>null</tt>, this constructor does not
	 * throw an exception. However, trying to invoke other methods on the
	 * resulting <tt>StringTokenizer</tt> may result in a
	 * <tt>NullPointerException</tt>.
	 * 
	 * @param str
	 *            a string to be parsed.
	 * @param delim
	 *            the delimiters.
	 * @param returnDelims
	 *            flag indicating whether to return the delimiters as tokens.
	 * @return String[]
	 */
	public static String[] stringToArray(String str, String delim,
			boolean returnDelims) {
		String[] result = null;
		if (str == null || "".equals(str)) {
			return new String[0];
		}
		StringTokenizer st = new java.util.StringTokenizer(str, delim,
				returnDelims);
		int attCnt = st.countTokens();
		if (attCnt > 0) {
			result = new String[attCnt];
		}
		int i = 0;
		while (st.hasMoreTokens()) {
			result[i] = (String) st.nextToken();
			i++;
		}
		return result;
	}

	/**
	 * Constructs an array of string token for the specified string. The
	 * characters in the <code>delim</code> argument are the delimiters for
	 * separating tokens. Delimiter characters themselves will not be treated as
	 * tokens.
	 * 
	 * @param str
	 *            a string to be parsed.
	 * @param delim
	 *            the delimiters.
	 * @return String[]
	 */
	public static String[] stringToArray(String str, String delim) {
		return stringToArray(str, delim, false);
	}

	/**
	 * Constructs a vector of string token for the specified string. All
	 * characters in the <code>delim</code> argument are the delimiters for
	 * separating tokens.
	 * 
	 * <p>
	 * If the <code>returnDelims</code> flag is <code>true</code>, then the
	 * delimiter characters are also returned as tokens. Each delimiter is
	 * returned as a string of length one. If the flag is <code>false</code>,
	 * the delimiter characters are skipped and only serve as separators between
	 * tokens.
	 * <p>
	 * Note that if <tt>delim</tt> is <tt>null</tt>, this constructor does not
	 * throw an exception. However, trying to invoke other methods on the
	 * resulting <tt>StringTokenizer</tt> may result in a
	 * <tt>NullPointerException</tt>.
	 * 
	 * @param str
	 *            a string to be parsed.
	 * @param delim
	 *            the delimiters.
	 * @param returnDelims
	 *            flag indicating whether to return the delimiters as tokens.
	 * 
	 * @return Vector
	 */
	public static Vector stringToVector(String str, String delim,
			boolean returnDelims) {
		Vector v = new Vector();
		if (str == null) {
			return v;
		}
		StringTokenizer st = new StringTokenizer(str, delim, returnDelims);
		while (st.hasMoreTokens()) {
			v.add(st.nextToken());
		}
		return v;
	}

	/**
	 * Constructs a vector of string token for the specified string. The
	 * characters in the <code>delim</code> argument are the delimiters for
	 * separating tokens. Delimiter characters themselves will not be treated as
	 * tokens.
	 * 
	 * @param str
	 *            a string to be parsed.
	 * @param delim
	 *            the delimiters.
	 * @return Vector
	 */
	public static Vector stringToVector(String str, String delim) {
		return stringToVector(str, delim, false);
	}

	/**
	 * Constructs a list of string token for the specified string. All
	 * characters in the <code>delim</code> argument are the delimiters for
	 * separating tokens.
	 * 
	 * <p>
	 * If the <code>returnDelims</code> flag is <code>true</code>, then the
	 * delimiter characters are also returned as tokens. Each delimiter is
	 * returned as a string of length one. If the flag is <code>false</code>,
	 * the delimiter characters are skipped and only serve as separators between
	 * tokens.
	 * <p>
	 * Note that if <tt>delim</tt> is <tt>null</tt>, this constructor does not
	 * throw an exception. However, trying to invoke other methods on the
	 * resulting <tt>StringTokenizer</tt> may result in a
	 * <tt>NullPointerException</tt>.
	 * 
	 * @param str
	 *            a string to be parsed.
	 * @param delim
	 *            the delimiters.
	 * @param returnDelims
	 *            flag indicating whether to return the delimiters as tokens.
	 * 
	 * @return List
	 */
	public static List stringToList(String str, String delim,
			boolean returnDelims) {
		List v = new Vector();
		if (str == null) {
			return v;
		}
		StringTokenizer st = new StringTokenizer(str, delim);
		while (st.hasMoreTokens()) {
			String temp = st.nextToken().trim();
			if (!isEmpty(temp)) {
				v.add(temp);
			}
			// v.add(st.nextToken());
		}

		return v;
	}

	/**
	 * Constructs a list of string token for the specified string. The
	 * characters in the <code>delim</code> argument are the delimiters for
	 * separating tokens. Delimiter characters themselves will not be treated as
	 * tokens.
	 * 
	 * @param str
	 *            a string to be parsed.
	 * @param delim
	 *            the delimiters.
	 * @return List
	 */
	public static List stringToList(String str, String delim) {
		return stringToList(str, delim, false);
	}

	public static String trimString(String str) {
		return (null == str) ? "" : str.trim();
	}

	/**
	 * Insert the method's description here. Creation date: (3/10/2003 3:44:30
	 * PM)
	 * 
	 * @return java.lang.String
	 * @param v
	 *            java.util.Vector
	 * @param delim
	 *            java.lang.String
	 */
	public static String listToString(List v, String delim) {
		String result;
		if (v == null || v.isEmpty()) {
			result = "";
		} else {
			StringBuffer sb = new StringBuffer();
			Iterator i = v.iterator();
			// boolean first = true;
			while (i.hasNext()) {
				String temp = (String) i.next();
				if (temp != null) {
					sb.append(temp).append(delim);
				}
			}
			result = sb.toString();
			result = result.substring(0, result.length() - 1);
		}
		return result;
	}

	/**
	 * Convert String to UTF encoding
	 * 
	 * @param String
	 * @return String in UTF
	 */
	public static String getBytes(String name)
			throws UnsupportedEncodingException {
		String utfname = null;
		try {
			utfname = new String(name.getBytes("8859_1"), "UTF8");
		} catch (UnsupportedEncodingException e) {
			// utfname = name;
			throw e;
		}
		return utfname;
	}

	/**
	 * Convert String array to UTF encoding
	 * 
	 * @param String
	 *            array
	 * @return String array in UTF
	 */
	public static String[] getBytes(String[] name)
			throws UnsupportedEncodingException {
		String[] utfname = new String[name.length];
		try {
			for (int i = 0; i < name.length; i++) {
				utfname[i] = new String(name[i].getBytes("8859_1"), "UTF8");

			}
		} catch (UnsupportedEncodingException e) {
			// utfname = name;
			throw e;
		}
		return utfname;
	}

	/**
	 * Insert the method's description here. Creation date: (3/10/2003 3:44:30
	 * PM)
	 * 
	 * @return java.lang.String
	 * @param v
	 *            java.util.Vector
	 * @param delim
	 *            java.lang.String
	 */
	public static String arrayToString(String[] s, String delim) {
		String result;
		if (s == null) {
			result = "";
		} else {
			StringBuffer sb = new StringBuffer();
			int i = 0;
			int len = s.length;
			boolean first = true;
			while (i < len) {
				if (!first) {
					sb.append(delim);
				} else {
					first = false;
				}
				sb.append(s[i]);
				i++;
			}
			result = sb.toString();
		}
		return result;
	}

	/**
	 * Insert the method's description here. Creation date: (3/10/2003 3:44:30
	 * PM)
	 * 
	 * @return java.lang.String
	 * @param v
	 *            java.util.Vector
	 * @param delim
	 *            java.lang.String
	 */
	public static String vectorToString(Vector v, String delim) {
		String result;
		if (v == null || v.isEmpty()) {
			result = "";
		} else {
			StringBuffer sb = new StringBuffer();
			Iterator i = v.iterator();
			boolean first = true;
			while (i.hasNext()) {
				if (!first) {
					sb.append(delim);
				} else {
					first = false;
				}
				sb.append(i.next());
			}
			result = sb.toString();
		}
		return result;
	}

	public static String vectorToStringForSql(Vector v) {
		String result;
		if (v == null || v.isEmpty()) {
			result = "";
		} else {
			StringBuffer sb = new StringBuffer();
			Iterator i = v.iterator();
			boolean first = true;

			boolean isString;
			Object o = v.get(0);
			if (o instanceof String) {
				isString = true;
			} else {
				isString = false;
			}

			while (i.hasNext()) {
				if (!first) {
					sb.append(",");
				} else {
					first = false;
				}
				if (isString) {
					sb.append("'").append(i.next()).append("'");
				} else {
					sb.append(i.next());
				}

			}
			result = sb.toString();
		}
		return result;
	}

	public static String wrapParagraph(String input, int requiredLength) {
		StringBuffer result = new StringBuffer();
		int startPos = 0;
		int index = 0;
		while ((index = input.indexOf('\n', startPos)) != -1) {
			result.append(wrapLine(input.substring(startPos, index).trim(),
					requiredLength));
			startPos = index + 1;
		}
		result.append(wrapLine(input.substring(startPos), requiredLength));
		return result.toString();
	}

	public static String wrapLine(String input, int requiredLength) {
		StringBuffer result = new StringBuffer();
		int length = requiredLength;
		int lastBeginPos = 0;

		while (length < input.length() - 1) {
			char c = input.charAt(length);
			if (c != '\t' && c != ' ') {
				int check = length;
				length = getLatestTokenPosition(input, length);
				if (length == -1 || (check - length >= requiredLength)) {
					if (length == -1) {
						length = getFirstTokenPosition(input, length);
					} else {
						length = getFirstTokenPosition(input, check);
					}
				}
				if (length == Integer.MAX_VALUE) {
					length = input.length();
				}
			}
			String seg = input.substring(lastBeginPos, length).trim();
			if (seg.length() > 0) {
				result.append(seg).append('\n');
			}
			lastBeginPos = length;
			length += requiredLength;
		}
		String seg = input.substring(lastBeginPos, input.length()).trim();
		if (seg.length() > 0) {
			result.append(seg).append('\n');
		}
		return result.toString();
	}

	private static int getLatestTokenPosition(String input, int length) {
		int pos1 = input.lastIndexOf('\t', length);
		int pos2 = input.lastIndexOf(' ', length);
		return pos1 >= pos2 ? pos1 : pos2;
	}

	private static int getFirstTokenPosition(String input, int length) {
		int pos1 = input.indexOf('\t', length);
		int pos2 = input.indexOf(' ', length);
		pos1 = pos1 == -1 ? Integer.MAX_VALUE : pos1;
		pos2 = pos2 == -1 ? Integer.MAX_VALUE : pos2;

		return pos1 <= pos2 ? pos1 : pos2;
	}

	/**
	 * lPadString returns String, left-padded to length <i>n</i> with <i>s</i>,
	 * replicated as many times as necessary; If <i>input</i> is longer than
	 * <i>length</i>, then this method returns the portion of <i>input</i> that
	 * fits in <i>length</i>. (Similar to Oracle lpad)
	 */
	public static String lPadString(String input, String s, int length) {
		if (input == null) {
			return input;
		} else if (input.length() >= length) {
			return input.substring(0, length);
		}

		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < length - input.length(); i++) {
			sb.append(s);
			if (sb.length() >= (length - input.length())) {
				break;
			}
		}
		sb = new StringBuffer(sb.substring(0, length - input.length()));
		return sb.append(input).toString();
	}

	/**
	 * rPadString returns String, right-padded to length <i>n</i> with <i>s</i>,
	 * replicated as many times as necessary; If <i>input</i> is longer than
	 * <i>length</i>, then this method returns the portion of <i>input</i> that
	 * fits in <i>length</i>. (Similar to Oracle rpad)
	 */
	public static String rPadString(String input, String s, int length) {
		if (input == null) {
			return input;
		} else if (input.length() >= length) {
			return input.substring(0, length);
		}

		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < length - input.length(); i++) {
			sb.append(s);
			if (sb.length() >= (length - input.length())) {
				break;
			}
		}
		return sb.insert(0, input).substring(0, length).toString();
	}

	/**
	 * @return java.lang.String
	 * @param d
	 *            Double
	 * @param s
	 *            Integer
	 */
	public static String doubletostr(Double d, Integer s) {
		if (d == null) {
			return "";
		}
		String pattern = rPadString("0.", "0", 2 + s.intValue());
		if (s.intValue() == 0) {
			pattern = "0";
		}
		NumberFormat nf = new DecimalFormat(pattern);
		return nf.format(d);
	}

	public static String replaceString(String original, String toReplace,
			String replacement) {

		String newString = original;

		int index = 0;
		int count = 0;
		while (index != -1) {
			index = newString.indexOf(toReplace, count);
			if (index != -1) {
				if (index == 0) {
					newString = replacement
							+ newString.substring(toReplace.length());
				} else {
					newString = newString.substring(0, index) + replacement
							+ newString.substring(index + toReplace.length());

				}
				count = index - toReplace.length() + replacement.length() + 1;

			}
		}
		return newString;

	}

	public static boolean isInt(String str) {
		str = str.trim();
		try {
			Integer int_num = new Integer(0);
			int int_out = int_num.parseInt(str);
		} catch (NumberFormatException e) {
			return false;
		}
		return true;
	}

	
	public static boolean isLong(String str) {
		str = str.trim();
		try {
			Long long_num = new Long(0);
		      long_num.parseLong(str);
		} catch (NumberFormatException e) {
			return false;
		}
		return true;
	}
	
	
	
	public static boolean compareStringWithEmpty(String source1, String source2) {
		if (isEmpty(source1) && isEmpty(source2)) {
			return true;
		}
		if (!isEmpty(source1) && !isEmpty(source1)) {
			return source1.equals(source2);
		} else {
			return false;
		}
	}

	public static boolean isEmail(String email) {
		if (isEmpty(email)) {
			return false;
		}
		String emailPattern = "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
		return Pattern.matches(emailPattern, email);
	}

	public static String getRandomString(int length) {
		String base = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
		Random random = new Random();
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < length; i++) {
			int number = random.nextInt(base.length());
			sb.append(base.charAt(number));
		}
		return sb.toString();
	}

	public static String fuzzyString(String input) {
		String regex = "(\\S{1,2})(\\S{1,3})(\\S+)";
		return input.replaceAll(regex, "$1***$3");
	}
	
	 /**
	  * java生成随机数字和字母组合
	  * @param length[生成随机数的长度]
	  * @return
	  */
	public static String getCharAndNumr(int length) {
		String val = "";
		Random random = new Random();
		for (int i = 0; i < length; i++) {
			// 输出字母还是数字
			String charOrNum = random.nextInt(2) % 2 == 0 ? "char" : "num";
			// 字符串
			if ("char".equalsIgnoreCase(charOrNum)) {
				// 取得大写字母还是小写字母
				int choice = random.nextInt(2) % 2 == 0 ? 65 : 97;
				val += (char) (choice + random.nextInt(26));
			} else if ("num".equalsIgnoreCase(charOrNum)) { // 数字
				val += String.valueOf(random.nextInt(10));
			}
		}
		return val;
	}
	
	/**
	 * 遮罩银行卡号，添加*
	 * @param str
	 * @return
	 */
	public static String shadeNumberToStar(String str){
		StringBuffer result=new StringBuffer();
		//前6
		String prefix=str.substring(0, 6);
		//后4
		String suffix=str.substring(str.length()-4);
		result.append(prefix);
		result.append("*********");
		result.append(suffix);
		return result.toString();
	}

	 
}
